/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TelaPrincipalView.java
 *
 * Created on 22/03/2013, 11:32:23
 */

package view;

import javax.swing.JPanel;
import javax.swing.tree.DefaultMutableTreeNode;
import view.dialog.SenhaJDialog;

/**
 *
 * @author Gabriel Menezes
 */
public final class TelaPrincipalView extends javax.swing.JFrame {

    /** Creates new form TelaPrincipalView */
    public TelaPrincipalView() {
        initComponents();
        setMainPanel(new ExibicaoJPanel()); 
        setVisible(true);
    }

    public void setMainPanel(javax.swing.JPanel mainPanel) {

        if (painelPrincipal != null) remove(painelPrincipal);

        painelPrincipal = mainPanel;

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(painelPrincipal);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 671, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 403, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(painelPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 593, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(painelPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        pack();
        setLocationRelativeTo(null);
        setExtendedState(MAXIMIZED_BOTH);
        painelPrincipal.setVisible(true);

    }

    public JPanel getMainPanel() {
        return painelPrincipal;
    }
    
    public void exibeJanelaSenha() {
        SenhaJDialog senhaJDialog = new SenhaJDialog();
        senhaJDialog.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        menuPrincipal = new javax.swing.JTree();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Gerenciador do Viveiro de Mudas CLIN");

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("Menu Principal");
        javax.swing.tree.DefaultMutableTreeNode treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Administrador");
        javax.swing.tree.DefaultMutableTreeNode treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Usuários");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Domínios");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Espécies");
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Pragas e Doenças");
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Árvores e Conjuntos Matrizes");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Controle de Matrizes");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Coletas Candidatas");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Lotes");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Lotes de Sementes");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Lotes de Mudas");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Registro de Saída");
        treeNode1.add(treeNode2);
        menuPrincipal.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        menuPrincipal.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                menuPrincipalMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(menuPrincipal);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Atividades Pendentes"));

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jTextArea1.setEnabled(false);
        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 651, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 593, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void menuPrincipalMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_menuPrincipalMouseClicked
        try {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) menuPrincipal.getSelectionPath().getLastPathComponent();
            String nomeSelecionado = node.getUserObject().toString();
            
            if (nomeSelecionado.equalsIgnoreCase("Menu Principal")) {
                if (!(painelPrincipal instanceof ExibicaoJPanel)) {
                    setMainPanel(new ExibicaoJPanel());
                }
                return;
            }
            
            if (nomeSelecionado.equalsIgnoreCase("Espécies")) {
                if (!(painelPrincipal instanceof ConsultaEspecieJPanel)) {
                    setMainPanel(new ConsultaEspecieJPanel(this));
                }
                return;
            }
            
            if (nomeSelecionado.equalsIgnoreCase("Usuários")) {
                if (!(painelPrincipal instanceof ConsultaUsuarioJPanel)) {
                    setMainPanel(new ConsultaUsuarioJPanel(this));
                }
                return;
            }
            
            if (nomeSelecionado.equalsIgnoreCase("Domínios")) {
                if (!(painelPrincipal instanceof ConsultaEspecieJPanel)) {
                    setMainPanel(new ConsultaDominioJPanel());
                }
                return;
            }
            
            if (nomeSelecionado.equalsIgnoreCase("Pragas e Doenças")) {
                if (!(painelPrincipal instanceof ConsultaPragaDoencaJPanel)) {
                    setMainPanel(new ConsultaPragaDoencaJPanel(this));
                }
                return;
            }
            
            if (nomeSelecionado.equalsIgnoreCase("Controle de Matrizes")) {
                if (!(painelPrincipal instanceof ConsultaMatrizJPanel)) {
                    setMainPanel(new ConsultaMatrizJPanel());
                }
                return;
            }
            
            if (nomeSelecionado.equalsIgnoreCase("Coletas Candidatas")) {
                if (!(painelPrincipal instanceof ColetaCandidataJPanel)) {
                    setMainPanel(new ColetaCandidataJPanel());
                }
                return;
            }
            
            if (nomeSelecionado.equalsIgnoreCase("Lotes de Sementes")) {
                if (!(painelPrincipal instanceof ConsultaLoteSementesJPanel)) {
                    setMainPanel(new ConsultaLoteSementesJPanel(this));
                }
                return;
            }
            
            if (nomeSelecionado.equalsIgnoreCase("Lotes de Mudas")) {
                if (!(painelPrincipal instanceof ConsultaLoteMudaJPanel)) {
                    setMainPanel(new ConsultaLoteMudaJPanel(this));
                }
                return;
            }
            
            if (nomeSelecionado.equalsIgnoreCase("Registro de Saída")) {
                if (!(painelPrincipal instanceof ConsultaRegistroSaidaJPanel)) {
                    setMainPanel(new ConsultaRegistroSaidaJPanel());
                }
                return;
            }
            
        } catch (NullPointerException e) {
            return;
        }
        return;
    }//GEN-LAST:event_menuPrincipalMouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        TelaPrincipalView tp = new TelaPrincipalView();
        tp.exibeJanelaSenha();
    }
    private javax.swing.JPanel painelPrincipal;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTree menuPrincipal;
    // End of variables declaration//GEN-END:variables

}
